package com.dtx.qiku.utils;

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;

public class FieldUtils {

    private FieldUtils(){}

    /**
     * 打印全部的属性变量
     * @param clazz
     * @throws Exception
     */
    public static void printFields(Class clazz) throws Exception {
        Field[] declaredFields = clazz.getDeclaredFields();
        Constructor constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        for (Field declaredField : declaredFields) {
            declaredField.setAccessible(true);
            System.out.println(declaredField.getName()+"成员变量的值为"+declaredField.get(constructor.newInstance()));
        }
    }

    public static void main(String[] args) throws Exception {

        printFields(Collections.class);
    }


}
